package com.hxkcloud.nurse.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hxkcloud.nurse.R;

import java.util.List;

/**
 * Created by ray_lei on 2016/7/7.
 */
public class HistoryRecordAdapter extends BaseAdapter {


    private List<String> records;

    private LayoutInflater mInflater;//得到一个LayoutInfalter对象用来导入布局


    /**构造函数*/
    public HistoryRecordAdapter(Context context,List<String> recordInfos) {
        this.mInflater = LayoutInflater.from(context);
        this.records = recordInfos;
    }

    @Override
    public int getCount() {
        return records.size();//返回数组的长度
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    /**书中详细解释该方法*/
    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        //观察convertView随ListView滚动情况
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.record_item_list,null);
            holder = new ViewHolder();
            /**得到各个控件的对象*/
            holder.layout = (LinearLayout) convertView.findViewById(R.id.record_layout);
            holder.name = (TextView) convertView.findViewById(R.id.record_tv_name);
            holder.notlastView = (View) convertView.findViewById(R.id.record_notlast);
            holder.lastView = (View) convertView.findViewById(R.id.record_last);
            convertView.setTag(holder);//绑定ViewHolder对象
        }
        else{
            holder = (ViewHolder)convertView.getTag();//取出ViewHolder对象
        }
        /**设置TextView显示的内容，即我们存放在动态数组中的数据*/
        holder.name.setText(records.get(position));
        if(position == records.size()-1){
            holder.lastView.setVisibility(View.VISIBLE);
            holder.notlastView.setVisibility(View.GONE);
        }else{
            holder.lastView.setVisibility(View.GONE);
            holder.notlastView.setVisibility(View.VISIBLE);
        }




        return convertView;
    }



    /**存放控件*/
    public final class ViewHolder{
        public LinearLayout layout;
        public TextView name;

        public View notlastView;
        public View lastView;

    }
}
